import { SETUSERINFO } from './action-types'
import { test, login, getList } from '../api'
export function setUserInfo(info) {
  return {
    type: SETUSERINFO,
    info: info
  }
}

export function testApi() {
  return test()
}
export function loginAction(params) {
  return function (dispatch) {
    return login(params).then(data => {
      if (data.resultCode == 200) {
        dispatch({
          type: SETUSERINFO,
          info: {
            token: data.data,
            isLogin: true
          }
        })
        localStorage.setItem("xf_user_info", JSON.stringify({
          token: data.data,
          isLogin: true
        }))
        return data
      }
      return Promise.reject()
    })
  }
}

export function getListAction(params) {
  return getList(params)
}